package com.example.activitytest;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;
import android.widget.Toast;

public class SecondActivity extends BaseActivity {
    private static final String TAG = "SecondActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_layout);
        // 接受Intent数据
        Intent intt = getIntent();
        String userName = intt.getStringExtra("extra_data");
        Log.d(TAG, userName);
        Button b2 = (Button) findViewById(R.id.button_2);
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 点击b2按钮向上返回数据
                Intent intt = new Intent();
                intt.putExtra("data_return","i'm b2!");
                setResult(RESULT_OK,intt);
                finish();

            }
        });
        Button bexit = (Button) findViewById(R.id.exit);
        bexit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 销毁当前活动
                finish();
            }
        });
    }
    // 按下back返回键也能向上返回数据：按下back会调用onBackPressed()这个函数
    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("data_return", "I'm back!");
        setResult(RESULT_OK, intent);
        finish();
    }
}